package com.zzr.demo.redis.controller;

import com.zzr.demo.redis.service.LocationDisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: xiaomi
 * @date: 2021/10/11
 * @description:
 */
@RestController
@RequestMapping("location/dist")
@Api(tags = "地理位置：设置、获取 地理位置，计算地理位置之间的距离")
@Slf4j
public class LocationDisController {

    @Autowired
    LocationDisService locationDisService;

    /**
     * peter
     * tom
     * jack
     *
     * @param longitude
     * @param latitude
     * @param name
     * @return
     */
    @GetMapping("/addLoc/{longitude}/{latitude}/{name}")
    @ApiOperation("添加坐标")
    public boolean addLoc(@PathVariable("longitude") double longitude, @PathVariable("latitude") double latitude, @PathVariable("name") String name) {
        locationDisService.addLoc(longitude, latitude, name);
        return true;
    }

    @GetMapping("/getLoc/{name}")
    @ApiOperation("获取地理的坐标")
    public String getLoc(@PathVariable("name") String name) {
        String loc = locationDisService.getLoc(name);
        return loc;
    }

    @GetMapping("/calLoc/{name1}/{name2}")
    @ApiOperation("计算两个位置之间的距离")
    public double calLoc(@PathVariable("name1") String name1, @PathVariable("name2") String name2) {
        double v = locationDisService.calLoc(name1, name2);
        return v;
    }


    @GetMapping("/nearby/{name}/{kms}")
    @ApiOperation("查询 name 的附近位置")
    public List<String> nearby(@PathVariable("name") String name, @PathVariable("kms") int kms) {
        List<String> nearby = locationDisService.nearby(name, kms);
        return nearby;
    }

}
